import sys
from PyQt5.QtWidgets import QApplication, QRadioButton, QWidget, QVBoxLayout, QGroupBox, QHBoxLayout


# class MyWindow(QWidget):
#     def __init__(self):
#         # 调用父类init方法
#         super().__init__()
#
#         self.resize(800, 500)
#
#         # 设置布局
#         layout = QVBoxLayout()  # V 垂直  H 水平
#
#         btn1 = QPushButton('按钮1')
#         btn2 = QPushButton('按钮2')
#         btn3 = QPushButton('按钮3')
#
#         # 按钮不设置Parent, 而是加入到布局中
#         layout.addWidget(btn1)
#         layout.addWidget(btn2)
#         layout.addWidget(btn3)
#
#         # 添加一个伸缩器 (理解为弹簧)
#         # 多个弹簧时可以传参, 数字之比就是所占空间之比
#         layout.addStretch()
#
#         # 让当前窗口使用该排列规则
#         self.setLayout(layout)


class MyWindow(QWidget):
    def __init__(self):
        # 调用父类init方法
        super().__init__()
        self.init_ui()

    # ui设置独立为一个方法
    def init_ui(self):
        self.resize(500, 400)
        self.setWindowTitle('Choose!')
        container = QVBoxLayout()

        # 嵌套布局器
        hoppy_box = QGroupBox()
        v_layout = QVBoxLayout()

        # QRadioButton 单选按钮
        r_btn1 = QRadioButton('唱')
        r_btn2 = QRadioButton('跳')
        r_btn3 = QRadioButton('rap')

        v_layout.addWidget(r_btn1)
        v_layout.addWidget(r_btn2)
        v_layout.addWidget(r_btn3)

        hoppy_box.setLayout(v_layout)

        gender_box = QGroupBox()
        h_layout = QHBoxLayout()

        r_btn4 = QRadioButton('男')
        r_btn5 = QRadioButton('女')
        r_btn6 = QRadioButton('其他')

        h_layout.addWidget(r_btn4)
        h_layout.addWidget(r_btn5)
        h_layout.addWidget(r_btn6)

        gender_box.setLayout(h_layout)

        # 记得将小的布局器添加到大的布局器中
        container.addWidget(hoppy_box)
        container.addWidget(gender_box)

        self.setLayout(container)


if __name__ == '__main__':
    app = QApplication(sys.argv)

    mw = MyWindow()
    mw.show()

    app.exec_()
